package com.connector.base.exception;

import io.netty.channel.*;
import io.netty.util.concurrent.GenericFutureListener;

import java.net.SocketAddress;

public class ExceptionHandler extends ChannelDuplexHandler
{
    public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
    }

    public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {
        ctx.connect(remoteAddress, localAddress, promise.addListener((GenericFutureListener)new ChannelFutureListener() {
            public void operationComplete(final ChannelFuture future) {
                if (!future.isSuccess()) {}
            }
        }));
    }

    public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
        ctx.write(msg, promise.addListener((GenericFutureListener)new ChannelFutureListener() {
            public void operationComplete(final ChannelFuture future) {
                if (!future.isSuccess()) {}
            }
        }));
    }
}
